<?php

class WXJSSDK {

    public function __construct() {

        //if(!$_SESSION['openid']) $this->getSignPackage();
        $this->getSignPackage();
    }

    public function getSignPackage()
    {
        $openid = null;
        $nick = null;
        if ($_GET['code']) {
            $code = $_GET['code'];
            $data = json_encode(array("code" => $code));

            $res = curl_fn($data, API_IP . 'hwcrmweb/wechat/auth/getUserInfoByCode.do');

            $res = json_decode($res, true);

            $openid = $res['data']['openId'];
            $nick = $res['data']['name'];
            $headimgurl = $res['data']['headimgurl'];

            /*$openid = 'ohBGVjmwiyfOCMs1GMiNuULpQHUk';
            $nick = '想歪了';*/

            if(!$openid){
                $url ="Refresh:1;url=https://wx.hotwind.net/emoticon/";
                header($url);
            }


            //开始捕捉
//            $str = file_get_contents($headimgurl);
//            $str = base64_encode($str);
//            dump($str);

            $_SESSION['openid'] = $openid;
            $_SESSION['nick'] = $nick;
            $_SESSION['headimgurl'] = $headimgurl;
        }
    }
}